$(function () {
var height_one = $('#wrapper').height()
var height_two = $('#img').height()
if (height_one > height_two) {
    $('#mask').css('height', height_one)
} else {
    $('#mask').css('height', height_two)
}
// 格子位置
var step_num = 0;
//骰子数字
var dice_num_one = 0;
var dice_num_two = 0;
    // 点击掷筛骰子
    $("#diceIcon").click(function(){
        $('#mask').show()
        var diceIcon = $("#diceIcon");
        var chars_one = parseInt((6*Math.random())+1);//取1-6的随机数
        var chars_two = parseInt((6*Math.random())+1);
        dice_num_one = chars_one;
        dice_num_two = chars_two;
        step_num = dice_num_one + dice_num_two;
        var szSet = setInterval(function() {
            var sj_one = parseInt((6*Math.random())+1);
            var sj_two = parseInt((6*Math.random())+1);
            $('#mask-sz-one').attr('src', './image/tz' + sj_one + '.png')
            $('#mask-sz-two').attr('src', './image/tz' + sj_two + '.png')
        }, 150)
        setTimeout(function() {
            clearInterval(szSet)
            dicrAmation(dice_num_one, dice_num_two)
            setTimeout(diceShow,1500);
            setTimeout(_kubaoMove(step_num),1500);
        }, 3000)
    })
})
function dicrAmation (dirone, dirtwo) {
    $('#mask-sz-one').attr('src', './image/tz' + dirone + '.png')
    $('#mask-sz-two').attr('src', './image/tz' + dirtwo + '.png')
}
// 点击投骰子按钮消失后显示
function diceShow(){
    $("#mask").hide();
}
//创建函数，用于返回一个无参数函数
function _kubaoMove(step){
       return function(){
             moveStep(step);
       }
}

function moveStep (step) {
    var luck_li = $(".luck-draw li");
    var index = 0;
    var index_step = 0;
    // console.log($(".luck-draw li").eq(0).addClass())
    var moveInterval = setInterval(function () {
        if (index_step > 0) luck_li.eq(index_step).addClass('border-active').siblings('li').removeClass('border-active');
        index ++;
        index_step ++ ;
        if (index > 9 && index % 9 === 1) {
            index_step = 1;
        }
        if (index > step) {
            clearInterval(moveInterval)
            console.log(index_step - 1)
            if (index_step - 1 === 0) {
                index_step = 10 
            }
            gonext(index_step)
            index_step = 0;
            index = 0;
            step_num = 0;
        }
    }, 250)
}
function gonext (index_step) {
    setTimeout(function() {
        goInformation(index_step - 1)
        luck_li.eq(index_step - 1).removeClass('border-active')
    }, 250)
}
function goInformation (index) {
    if ( index === 3 || index === 5 || index === 7 ||index === 6 || index === 9) {
        window.location.href = './print.html?index='+index
    } else {
        window.location.href = './information.html?index='+index
    }
}